package com.liu.susu.thread.task.async.async2.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;


/**
 * @FileName AsyncTaskServiceImpl
 * @Description
 * @Author susu
 * @date 2022-03-09
 **/
@Service
@Slf4j
public class AsyncTaskServiceImpl implements AsyncTaskService{

    private final String ASYNC_TASK_EXECUTOR = "getSuSuAsyncTaskExecutor2";//getSuSuAsyncTaskExecutor1

    @Override
//    @Async("getSuSuAsyncTaskExecutor1")
    @Async(ASYNC_TASK_EXECUTOR)
    public void doMyTask1() {
        log.info("begin doMyTask1()...");
        long currentTimeMillis = System.currentTimeMillis();
        try {
            Thread.sleep(2100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long currentTimeMillis1 = System.currentTimeMillis();
        log.info("end doMyTask1()-->doMyTask1任务耗时:"+(currentTimeMillis1-currentTimeMillis)+"ms");

    }
    @Override
    @Async(ASYNC_TASK_EXECUTOR)
    public void doMyTask2() {
        log.info("begin doMyTask2()...");

        long currentTimeMillis = System.currentTimeMillis();
        try {
            Thread.sleep(3100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long currentTimeMillis1 = System.currentTimeMillis();

        log.info("end doMyTask2()-->doMyTask2任务耗时:"+(currentTimeMillis1-currentTimeMillis)+"ms");
    }

    @Override
    @Async(ASYNC_TASK_EXECUTOR)
    public void doMyTask3() {
        log.info("begin doMyTask3()...");

        long currentTimeMillis = System.currentTimeMillis();
        try {
            Thread.sleep(1600);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long currentTimeMillis1 = System.currentTimeMillis();

        log.info("end doMyTask3()-->doMyTask3任务耗时:"+(currentTimeMillis1-currentTimeMillis)+"ms");
    }


}
